package ComputerOrganization;

/**
 * @Author maojiangyue
 * @Date 2025/10/10
 * @Description
 */
public class Computer {
    private CPU cpu;
    private Memory memory;
    private Motherboard motherboard;
    private Monitor monitor;

    //类似组装电脑的构造方法
    public Computer(CPU cpu, Memory memory, Motherboard motherboard, Monitor monitor) {
        this.cpu = cpu;
        this.memory = memory;
        this.motherboard = motherboard;
        this.monitor = monitor;
    }

    //开机方法
    public void powerOn() {
        System.out.println("=== 正在启动电脑 ===");
        motherboard.powerOn();
        motherboard.connectComponents();
        cpu.start();
        memory.load();
        monitor.turnOn();
        System.out.println("=== 电脑启动完成 ===\n");
    }

    //运行程序
    public void runProgram(String programName) {
        System.out.println("正在运行程序: " + programName);
        memory.storeData(programName + " 的运行数据");
        cpu.execute("运行 " + programName);
        monitor.display("欢迎使用 " + programName + "！");
    }

    //关机
    public void shutdown() {
        System.out.println("\n电脑正在关机...");
        System.out.println("所有组件已断电\n");
    }
}
